package com.yuqian.JavaSe.leetcode.easy;

/**
 * Definition for a binary tree node. public class TreeNode { int val; TreeNode
 * left; TreeNode right; TreeNode(int x) { val = x; } }
 * 
 * 求二叉树的高度
 */
public class MaximumDepthofBinaryTree {
	public int maxDepth(TreeNode root) {
		if(root==null){
			return 0;
		}
		if(root.left==null&&root.right==null){
			return 1;
		}else{
			int leftDepth = maxDepth(root.left);
			int rightDepth = maxDepth(root.right);
			int max =  leftDepth>rightDepth?leftDepth:rightDepth;
			return 1+max;
		}

	}

	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}
}
